package frame.m.com.mylibrary.common;

import android.app.Activity;
import android.content.Context;

import com.blankj.utilcode.util.ToastUtils;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

/**
 * app的各种提示框
 * Created by Administrator on 2017/7/20.
 */

public class HintView {
    private static HintView instance;
    private Context mContext;
    private QMUITipDialog mDialog;

    private HintView() {

    }

    public static HintView getInstance() {
        if (instance == null) {
            synchronized (HintView.class) {
                if (instance == null) {
                    instance = new HintView();
                }
            }
        }
        return instance;
    }


    public void showSuccess(String str) {


    }

    public void showError(String str) {
        ToastUtils.showShort(str);
    }

    public void showHint(String str) {
        ToastUtils.showShort(str);
    }

    public void showSuccess(Context context, String str) {
        mDialog = new QMUITipDialog.Builder(context).setIconType(QMUITipDialog.Builder
                .ICON_TYPE_SUCCESS)
                .setTipWord(str).create();
        mDialog.show();
        dismissDialog();
    }

    public void showError(Context context, String str) {
        mDialog = new QMUITipDialog.Builder(context).setIconType(QMUITipDialog.Builder
                .ICON_TYPE_FAIL)
                .setTipWord(str).create();
        mDialog.show();
        dismissDialog();
    }

    public void showHint(Context context, String str) {
        showHint(str);
    }

    public void dismissDialog(){
        Observable.timer(1500, TimeUnit.MILLISECONDS).subscribe(new Consumer<Long>() {
            @Override
            public void accept(Long aLong) throws Exception {
                if(mDialog!=null)
                {
                    mDialog.dismiss();
                    mDialog=null;
                }
            }
        });
    }

}
